//
//  ;
//  TencentAD
//
//  Created by 刘山 on 2017/8/23.
//  Copyright © 2017年 Sam. All rights reserved.
//

#import "SEGAlerViewHUD.h"
static SEGAlerViewHUD *_instance = nil;
@interface SEGAlerViewHUD()
/**
 中奖黄色背景-砸金蛋
 */
@property (nonatomic, strong)UIImageView *bg_dialog_Winners;
/**
 没有中奖黄色背景-砸金蛋
 */
@property (nonatomic, strong)UIImageView *bg_dialog_Lose;

/**
 红包中奖黄色背景
 */
@property (nonatomic, strong)UIImageView *bg_dialog_WalletWinners;
/**
 红包没有中奖黄色背景
 */
@property (nonatomic, strong)UIImageView *bg_dialog_WalletLose;

/**
 恭喜中奖彩图
 */
@property (nonatomic, strong)UIImageView *img_dialogt;

/**
 红包上的宝箱图
 */
@property (nonatomic, strong)UIImageView *img_box;

/**
 关闭按钮
 */
@property (nonatomic, strong)UIButton *closeButton;

/**
 点击触发按钮
 */
@property (nonatomic, strong)UIButton *commitButton;

@property (nonatomic, strong)UILabel *appNameLabel;
@property (nonatomic, strong)UIImageView *appNameRightImageView;
@property (nonatomic, strong)UIImageView *appNameLeftImageView;

@property (nonatomic, strong)UILabel *contentLabel;
@property (nonatomic, strong)UIButton *checkAwardListBtn;

@end

@implementation SEGAlerViewHUD{
    AlerViewHUDBlock _block;
}

+ (SEGAlerViewHUD *)sharedView
{
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        _instance = [[self alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    });
    return _instance;
}

#pragma mark -初始化
-(instancetype)init{
    if (self == [super init]) {
        [self seg_setupUI];
    }
    return self;
}

-(instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self seg_setupUI];
    }
    return self;
}

-(void)seg_setupUI{
    [self setUserInteractionEnabled:YES];
    self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.8];
}

// 背景图切点九
- (UIImage *)resizableImageByName:(NSString *)imageName {
    if (!imageName || imageName.length == 0) {
        return nil;
    }
    UIImage *image = [UIImage imageWithContentsOfFile:SEGPicName(imageName)];
    CGFloat top = image.size.height - 11;
    CGFloat left = 100;
    CGFloat bottom = 10;
    CGFloat right = 100;
    /// 顶端、左端、底部、右端分别预留距离
    UIEdgeInsets insets = UIEdgeInsetsMake(top, left, bottom, right);
    //注意：拉伸之后一定要赋值回去
    image = [image  resizableImageWithCapInsets:insets resizingMode:UIImageResizingModeStretch];
    //UIImageResizingModeStretch：`拉伸`模式，通过`拉伸`Insets指定的矩形区域来填充图片
    //UIImageResizingModeTile：`平铺`模式，通过`重复显示`Insets指定的矩形区域来填充图片
    
    return image;
}

#pragma mark -显示
/**
 * 展示不同类型的弹窗
 * @author Sam
 * @param type  弹窗类型的枚举
 * @param prizeName  奖品名称
 * @param picUrl  奖品图片
 * @param trytime  剩余次数
 * @param notLotteryMsg 未中奖提示语
 * @param block  用户触发的回调
 */
+(void)show:(SEGAlerViewHUDType)type prizeName:(NSString*)prizeName picUrl:(NSString*)picUrl trytime:(NSInteger)trytime notLotteryMsg:(NSString *)notLotteryMsg finished:(AlerViewHUDBlock)block
{
    [[SEGAlerViewHUD sharedView] show:type prizeName:prizeName picUrl:picUrl trytime:trytime notLotteryMsg:notLotteryMsg finished:block];
}

-(void)show:(SEGAlerViewHUDType)type prizeName:(NSString*)prizeName picUrl:(NSString*)picUrl trytime:(NSInteger)trytime notLotteryMsg:(NSString *)notLotteryMsg finished:(AlerViewHUDBlock)block
{
    [self setUserInteractionEnabled:YES];
    [[[UIApplication sharedApplication] keyWindow] addSubview:self];
    
    _block = block;
    NSString *title;
    if (trytime == -100) {//特殊标记 触发抽奖 直接显示 我知道了
        title = @"我知道了";
    }else if(trytime > 0){
        title = @"再来一次";
    }else {
        title = @"您的抽奖机会已用完";
    }
    
//    NSNumber *test = @(7);
//    type = [test integerValue];

    self.contentLabel.numberOfLines = 0;
    self.contentLabel.lineBreakMode = NSLineBreakByCharWrapping;
    
    switch (type) {
        case SEGAlerViewHUDType_EggWin:
        {
            [self seg_WinWithImageView:@"bg_activity03_dialog" buttonTitle:@"查看奖品" buttonImage:@"btn_activity03_dialog"];
            [self seg_contentNarmal:[NSString stringWithFormat:@"恭喜您获得%@",prizeName] font:16.0 textColor:[UIColor colorWithRed:213.0/255.0 green:72.0/255.0 blue:63.0/255.0 alpha:1]];
            break;
        }
        case SEGAlerViewHUDType_EggWinRecord:
        {
            [self seg_contentLogicRecord:prizeName];
            [self seg_WinWithImageView1:@"bg_activity03_dialog" buttonTitle:title buttonImage:@"btn_activity03_dialog"];
            break;
        }
        case SEGAlerViewHUDType_EggLose:
        {
            [self seg_contentNarmal:notLotteryMsg font:16.0 textColor:[UIColor colorWithRed:213.0/255.0 green:72.0/255.0 blue:63.0/255.0 alpha:1]];
            [self seg_LoseWithImageView:@"bg_activity03_dialog02" buttonTitle:title buttonImage:@"btn_activity03_dialog"];
            break;
        }
        case SEGAlerViewHUDType_TurnTableWin:
        {
            [self seg_contentNarmal:[NSString stringWithFormat:@"恭喜您获得%@",prizeName] font:16.0 textColor:[UIColor colorWithRed:255.0/255.0 green:88.0/255.0 blue:88.0/255.0 alpha:1]];
            [self seg_WinWithImageView:@"bg_activity01_dialog" buttonTitle:@"查看奖品" buttonImage:@"btn_activity01_dialog"];
            break;
        }
        case SEGAlerViewHUDType_TurnTableWinRecord:
        {
            [self seg_contentLogicRecord:prizeName];
            [self seg_WinWithImageView1:@"bg_activity01_dialog" buttonTitle:title buttonImage:@"btn_activity01_dialog"];
            break;
        }
        case SEGAlerViewHUDType_TurnTableLose:
        {
            [self seg_contentNarmal:notLotteryMsg font:16.0 textColor:[UIColor colorWithRed:213.0/255.0 green:88.0/255.0 blue:88.0/255.0 alpha:1]];
            [self seg_LoseWithImageView:@"bg_activity01_dialog02" buttonTitle:title buttonImage:@"btn_activity01_dialog"];
            break;
        }
        case SEGAlerViewHUDType_NarmalWin:
        {
            [self seg_contentNarmal:[NSString stringWithFormat:@"恭喜您获得%@",prizeName] font:13.0 textColor:[UIColor colorWithRed:247.0/255.0 green:49.0/255.0 blue:33.0/255.0 alpha:1]];
            [self seg_WinNormalWithImageView:@"img_hongbao_open_01" buttonTitle:@"查看奖品"];
            self.contentLabel.numberOfLines = 2;
            self.contentLabel.lineBreakMode = NSLineBreakByTruncatingTail;
            self.bg_dialog_WalletWinners.image = [UIImage imageWithContentsOfFile:SEGPicName(@"img_hongbao_open_01")];
            [self.bg_dialog_WalletWinners mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.center.equalTo(self);
                make.width.mas_equalTo(270);
                make.height.mas_equalTo(329);
            }];
            break;
        }
        case SEGAlerViewHUDType_NarmalLose:
        {
            [self seg_contentNarmal:notLotteryMsg font:16.0 textColor:[UIColor colorWithRed:247.0/255.0 green:49.0/255.0 blue:33.0/255.0 alpha:1]];
            [self seg_LoseNormalWithImageView:@"img_hongbao_open_02" buttonTitle:title];
            break;
        }
    }
    
    [self.img_box setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kClientImageRootURL,picUrl]] placeholderImage:[UIImage imageWithContentsOfFile:SEGPicName(@"pic_default_300_300")]];
}

-(void)seg_colse{
    _block(SEGAlerViewHUDResult_Close);
    [self removeFromSuperview];
    [self ddd];
}

-(void)seg_tryAgin:(UIButton*)sender{
    if ([sender.titleLabel.text isEqualToString:@"我知道了"]) {
        _block(SEGAlerViewHUDResult_Know);
    }
    
    if ([sender.titleLabel.text isEqualToString:@"查看奖品"]) {
        _block(SEGAlerViewHUDResult_ShowPrize);
    }
    
    if ([sender.titleLabel.text isEqualToString:@"再来一次"]) {
        _block(SEGAlerViewHUDResult_TryAgin);
    }
    
    if ([sender.titleLabel.text isEqualToString:@"您的抽奖机会已用完"]) {
        _block(SEGAlerViewHUDResult_LastTime);
    }
    
    [self removeFromSuperview];
    [self ddd];
}


-(void)seg_WinWithImageView:(NSString*)backgroundImage buttonTitle:(NSString*)btnTitle buttonImage:(NSString*)btnImage
{
    //防止之前有内容显示
    self.checkAwardListBtn.hidden = YES;
    self.contentLabel.hidden = NO;
    
    self.bg_dialog_Winners.image = [self resizableImageByName:backgroundImage];
    [self addSubview:self.bg_dialog_Winners];
    
    [self.bg_dialog_Winners addSubview:self.img_box];
    [self.img_box mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(80);
        make.top.equalTo(self.bg_dialog_Winners.mas_top).mas_offset(50);
        make.centerX.equalTo(self.bg_dialog_Winners);
    }];
    
    [self.bg_dialog_Winners addSubview:self.img_dialogt];
    [self.img_dialogt mas_makeConstraints:^(MASConstraintMaker *make) {
        CGFloat W = 270;
        CGFloat Y = W/2.25;
        make.width.mas_equalTo(W);
        make.height.mas_equalTo(Y);
        make.bottom.equalTo(self.img_box.mas_top).mas_offset(3);
        make.centerX.equalTo(self.bg_dialog_Winners);
    }];
    
    [self addSubview:self.closeButton];
    [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.img_dialogt.mas_right);
        make.top.equalTo(self.img_dialogt.mas_top);
        make.width.height.mas_equalTo(self.closeButton.bounds.size.width);
    }];
    
    [self.bg_dialog_Winners addSubview:self.contentLabel];
    [self.bg_dialog_Winners setUserInteractionEnabled:YES];
    self.contentLabel.numberOfLines = 0;
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bg_dialog_Winners.mas_left).mas_offset(15);
        make.right.equalTo(self.bg_dialog_Winners.mas_right).mas_offset(-15);
        make.top.equalTo(self.img_box.mas_bottom).mas_offset(15);
    }];
    
    [self.bg_dialog_Winners addSubview:self.commitButton];
    [self.commitButton setTitle:btnTitle forState:UIControlStateNormal];
    [self.commitButton setBackgroundImage:[UIImage imageWithContentsOfFile:SEGPicName(btnImage)] forState:UIControlStateNormal];
    NSString *imageName = [NSString stringWithFormat:@"%@02",btnImage];
    [self.commitButton setBackgroundImage:[UIImage imageWithContentsOfFile:SEGPicName(imageName)] forState:UIControlStateHighlighted];
    [self.commitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bg_dialog_Winners).mas_offset(15);
        make.right.equalTo(self.bg_dialog_Winners).mas_offset(-15);
        make.top.equalTo(self.contentLabel.mas_bottom).mas_offset(20);
    }];
    
    [self.bg_dialog_Winners mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.mas_equalTo(230);
        make.bottom.equalTo(self.commitButton.mas_bottom).mas_offset(15);
    }];
}

-(void)seg_WinWithImageView1:(NSString*)backgroundImage buttonTitle:(NSString*)btnTitle buttonImage:(NSString*)btnImage
{
    self.checkAwardListBtn.hidden = NO;
    self.contentLabel.hidden = NO;
    
    self.bg_dialog_Winners.image = [self resizableImageByName:backgroundImage];
    
    [self addSubview:self.bg_dialog_Winners];
    [self.bg_dialog_Winners mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.mas_equalTo(230);
    }];
    
    [self.bg_dialog_Winners addSubview:self.img_box];
    [self.img_box mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(80);
        make.top.equalTo(self.bg_dialog_Winners.mas_top).mas_offset(50);
        make.centerX.equalTo(self.bg_dialog_Winners);
    }];
    
    [self.bg_dialog_Winners addSubview:self.img_dialogt];
    [self.img_dialogt mas_makeConstraints:^(MASConstraintMaker *make) {
        CGFloat W = 270;
        CGFloat Y = W/2.25;
        make.width.mas_equalTo(W);
        make.height.mas_equalTo(Y);
        make.bottom.equalTo(self.img_box.mas_top).mas_offset(3);
        make.centerX.equalTo(self.bg_dialog_Winners);
    }];
    
    [self addSubview:self.closeButton];
    [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.img_dialogt.mas_right);
        make.top.equalTo(self.img_dialogt.mas_top);
        make.width.height.mas_equalTo(self.closeButton.bounds.size.width);
    }];
    
    [self.bg_dialog_Winners addSubview:self.contentLabel];
    [self.bg_dialog_Winners setUserInteractionEnabled:YES];
    self.contentLabel.numberOfLines = 0;
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bg_dialog_Winners.mas_left).mas_offset(15);
        make.right.equalTo(self.bg_dialog_Winners.mas_right).mas_offset(-15);
        make.top.equalTo(self.img_box.mas_bottom).mas_offset(15);
    }];
    
    [self.bg_dialog_Winners addSubview:self.checkAwardListBtn];
    [self.checkAwardListBtn sizeToFit];
    [self.checkAwardListBtn.titleLabel sizeToFit];
    [self.checkAwardListBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLabel.mas_bottom).mas_offset(4);
        make.width.mas_equalTo(self.checkAwardListBtn.mas_width);
        make.centerX.equalTo(self.img_box);
    }];
    
    [self.bg_dialog_Winners addSubview:self.commitButton];
    [self.commitButton setTitle:btnTitle forState:UIControlStateNormal];
    [self.commitButton setBackgroundImage:[UIImage imageWithContentsOfFile:SEGPicName(btnImage)] forState:UIControlStateNormal];
    NSString *imageName = [NSString stringWithFormat:@"%@02",btnImage];
    [self.commitButton setBackgroundImage:[UIImage imageWithContentsOfFile:SEGPicName(imageName)] forState:UIControlStateHighlighted];
    [self.commitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bg_dialog_Winners).mas_offset(15);
        make.right.equalTo(self.bg_dialog_Winners).mas_offset(-15);
        make.top.equalTo(self.checkAwardListBtn.mas_bottom).mas_offset(20);
        make.height.mas_equalTo(46);
    }];
    
    [self.bg_dialog_Winners mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.mas_equalTo(230);
        make.bottom.equalTo(self.commitButton.mas_bottom).mas_offset(15);
    }];
    
}

-(void)seg_LoseWithImageView:(NSString*)backgroundImage buttonTitle:(NSString*)btnTitle buttonImage:(NSString*)btnImage
{
    //防止之前有内容显示
    self.checkAwardListBtn.hidden = YES;
    self.contentLabel.hidden = NO;
    
    self.bg_dialog_Lose.image = [UIImage imageWithContentsOfFile:SEGPicName(backgroundImage)];
    [self addSubview:self.bg_dialog_Lose];
    
    [self.bg_dialog_Lose mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.mas_equalTo(230);
    }];
    
    [self addSubview:self.closeButton];
    [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_bg_dialog_Lose.mas_right).mas_offset(self.closeButton.bounds.size.width * 0.5);
        make.top.equalTo(_bg_dialog_Lose.mas_top).mas_offset(-self.closeButton.bounds.size.width * 0.5);
        make.width.height.mas_equalTo(self.closeButton.bounds.size.width);
    }];
    
    [self.bg_dialog_Lose addSubview:self.img_box];
    [self.img_box mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(80);
        make.top.equalTo(_bg_dialog_Lose.mas_top).mas_offset(50);
        make.centerX.equalTo(_bg_dialog_Lose);
    }];
    
    [self.bg_dialog_Lose addSubview:self.contentLabel];
    [self.bg_dialog_Lose setUserInteractionEnabled:YES];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_bg_dialog_Lose).mas_offset(15);
        make.right.equalTo(_bg_dialog_Lose).mas_offset(-15);
        make.top.equalTo(self.img_box.mas_bottom).mas_offset(20);
    }];
    
    [self.bg_dialog_Lose addSubview:self.commitButton];
    [self.commitButton setTitle:btnTitle forState:UIControlStateNormal];
    [self.commitButton setBackgroundImage:[UIImage imageWithContentsOfFile:SEGPicName(btnImage)] forState:UIControlStateNormal];
    NSString *imageName = [NSString stringWithFormat:@"%@02",btnImage];
    [self.commitButton setBackgroundImage:[UIImage imageWithContentsOfFile:SEGPicName(imageName)] forState:UIControlStateHighlighted];
    [self.commitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_bg_dialog_Lose).mas_offset(15);
        make.right.equalTo(_bg_dialog_Lose).mas_offset(-15);
        make.bottom.equalTo(_bg_dialog_Lose).mas_offset(-15);
        make.top.equalTo(self.contentLabel.mas_bottom).mas_offset(20);
    }];
    
    [self.bg_dialog_Lose mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.mas_equalTo(230);
        make.bottom.equalTo(self.commitButton.mas_bottom).mas_offset(15);
    }];
}

-(void)seg_WinNormalWithImageView:(NSString*)backgroundImage buttonTitle:(NSString*)btnTitle{
    //防止之前有内容显示
    self.checkAwardListBtn.hidden = YES;
    self.contentLabel.hidden = NO;
    
    self.bg_dialog_WalletWinners.image = [UIImage imageWithContentsOfFile:SEGPicName(backgroundImage)];
    
    [self addSubview:self.bg_dialog_WalletWinners];
    [self.bg_dialog_WalletWinners mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.mas_equalTo(230);
    }];
    
    [self.bg_dialog_WalletWinners addSubview:self.img_dialogt];
    [self.img_dialogt mas_makeConstraints:^(MASConstraintMaker *make) {
        CGFloat W = 270;
        CGFloat Y = W/2.25;
        make.width.mas_equalTo(W);
        make.height.mas_equalTo(Y);
        make.top.equalTo(_bg_dialog_WalletWinners.mas_top);
        make.centerX.equalTo(_bg_dialog_WalletWinners);
    }];
    
    [self addSubview:self.closeButton];
    [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.img_dialogt.mas_right);
        make.top.equalTo(self.img_dialogt.mas_top);
        make.width.height.mas_equalTo(self.closeButton.bounds.size.width);
    }];
    
    [self.bg_dialog_WalletWinners addSubview:self.img_box];
    self.img_box.layer.cornerRadius = 2;
    self.img_box.layer.masksToBounds = YES;
    [self.img_box mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(50);
        make.top.equalTo(_bg_dialog_WalletWinners.mas_top).mas_offset(100);
        make.centerX.equalTo(_bg_dialog_WalletWinners);
    }];
    
    [self.bg_dialog_WalletWinners addSubview:self.commitButton];
    [self.commitButton setBackgroundImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_hongbao_open_01")] forState:UIControlStateNormal];
    [self.commitButton setBackgroundImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_hongbao_open_02")] forState:UIControlStateHighlighted];
    [self.commitButton setTitle:btnTitle forState:UIControlStateNormal];
    [self.commitButton.titleLabel setFont:[UIFont systemFontOfSize:16]];
    [self.commitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_bg_dialog_WalletWinners).mas_offset(15);
        make.right.equalTo(_bg_dialog_WalletWinners).mas_offset(-15);
        make.bottom.equalTo(_bg_dialog_WalletWinners).mas_offset(-15);
        make.height.mas_equalTo(46);
    }];
    
    [self.bg_dialog_WalletWinners addSubview:self.appNameLabel];
    [self.appNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_bg_dialog_WalletWinners);
        make.bottom.equalTo(self.commitButton.mas_top).mas_offset(-15);
    }];
    
    [self.bg_dialog_WalletWinners addSubview:self.appNameLeftImageView];
    [self.appNameLeftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.appNameLabel.mas_left).mas_offset(-15);
        make.centerY.equalTo(self.appNameLabel);
    }];
    
    [self.bg_dialog_WalletWinners addSubview:self.appNameRightImageView];
    [self.appNameRightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.appNameLabel.mas_right).mas_offset(15);
        make.centerY.equalTo(self.appNameLabel);
    }];
    
    [self.contentLabel sizeToFit];
    [self.bg_dialog_WalletWinners setUserInteractionEnabled:YES];
    [self.bg_dialog_WalletWinners addSubview:self.contentLabel];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_bg_dialog_WalletWinners.mas_left).mas_offset(40);
        make.right.equalTo(_bg_dialog_WalletWinners.mas_right).mas_offset(-40);
        make.top.equalTo(self.img_box.mas_bottom).mas_offset(10);
    }];
}


-(void)seg_LoseNormalWithImageView:(NSString*)backgroundImage buttonTitle:(NSString*)btnTitle{
    //防止之前有内容显示
    self.checkAwardListBtn.hidden = YES;
    self.contentLabel.hidden = NO;
    
    self.bg_dialog_WalletLose.image = [UIImage imageWithContentsOfFile:SEGPicName(backgroundImage)];
    
    [self addSubview:self.bg_dialog_WalletLose];
    [self.bg_dialog_WalletLose mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.mas_equalTo(230);
    }];
    
    [self addSubview:self.closeButton];
    [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_bg_dialog_WalletLose.mas_right).mas_offset(self.closeButton.bounds.size.width * 0.5);
        make.top.equalTo(_bg_dialog_WalletLose.mas_top).mas_offset(-self.closeButton.bounds.size.width * 0.5);
        make.width.height.mas_equalTo(self.closeButton.bounds.size.width);
    }];
    
    [_bg_dialog_WalletLose addSubview:self.commitButton];
    [self.commitButton setBackgroundImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_hongbao_open_01")] forState:UIControlStateNormal];
    [self.commitButton setBackgroundImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_hongbao_open_02")] forState:UIControlStateHighlighted];
    [self.commitButton setTitle:btnTitle forState:UIControlStateNormal];
    [self.commitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_bg_dialog_WalletLose).mas_offset(15);
        make.right.equalTo(_bg_dialog_WalletLose).mas_offset(-15);
        make.bottom.equalTo(_bg_dialog_WalletLose).mas_offset(-15);
        make.height.mas_equalTo(46);
    }];
    
    [self.bg_dialog_WalletLose addSubview:self.appNameLabel];
    [self.appNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(_bg_dialog_WalletLose);
        make.bottom.equalTo(self.commitButton.mas_top).mas_offset(-15);
    }];
    
    [self.bg_dialog_WalletLose addSubview:self.appNameLeftImageView];
    [self.appNameLeftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.appNameLabel.mas_left).mas_offset(-15);
        make.centerY.equalTo(self.appNameLabel);
    }];
    
    [self.bg_dialog_WalletLose addSubview:self.appNameRightImageView];
    [self.appNameRightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.appNameLabel.mas_right).mas_offset(15);
        make.centerY.equalTo(self.appNameLabel);
    }];
    
    [self.contentLabel sizeToFit];
    [self.bg_dialog_WalletLose setUserInteractionEnabled:YES];
    [self.bg_dialog_WalletLose addSubview:self.contentLabel];
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_bg_dialog_WalletLose.mas_left).mas_offset(30);
        make.right.equalTo(_bg_dialog_WalletLose.mas_right).mas_offset(-30);
        make.top.equalTo(_bg_dialog_WalletLose).mas_offset(50);
    }];
}

/**
 * 文本内容中有中奖记录的逻辑
 * @author Sam
 */
-(void)seg_contentLogicRecord:(NSString*)prizeName
{
    //防止之前有内容显示
    self.checkAwardListBtn.hidden = NO;
    self.contentLabel.hidden = NO;
    
    NSString *c1 = @"中奖记录";
    NSString *c3 = [NSString stringWithFormat:@"奖品已存放至 %@ 里",c1];
    
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:c3];
    
    [AttributedStr addAttributes:@{
                                   NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle)
                                   } range:[c3 rangeOfString:c1]];
    
    [AttributedStr addAttributes:@{
                                   NSFontAttributeName:[UIFont systemFontOfSize:12.0],
                                   NSForegroundColorAttributeName:[UIColor colorWithRed:255.0/255.0 green:88.0/255.0 blue:88.0/255.0 alpha:1]
                                   } range:[c3 rangeOfString:c3]];
    
    self.contentLabel.text = [NSString stringWithFormat:@"恭喜您获得%@", prizeName];
    self.contentLabel.textColor = [UIColor colorWithRed:213.0/255.0 green:72.0/255.0 blue:63.0/255.0 alpha:1];
    [self.checkAwardListBtn setTitle:@"奖品已存放至 中奖记录 里" forState:UIControlStateNormal];
    [self.checkAwardListBtn setAttributedTitle:AttributedStr forState:UIControlStateNormal];
    
}


-(void)seg_lotteryRecord{
    _block(SEGAlerViewHUDResult_WalletHistory);
    [self removeFromSuperview];
    [self ddd];
}

/**
 * 文本内容
 * @author Sam
 */
-(void)seg_contentNarmal:(NSString*)content font:(CGFloat)zise textColor:(UIColor*)textColor{
    [self.contentLabel setFont:[UIFont systemFontOfSize:zise]];
    [self.contentLabel setTextColor:textColor];
    self.contentLabel.text = content;
    [self.contentLabel sizeToFit];
}


-(UIImageView *)bg_dialog_Winners{
    if (!_bg_dialog_Winners) {
        _bg_dialog_Winners = [[UIImageView alloc]init];
        [_bg_dialog_Winners setUserInteractionEnabled:YES];
        [_bg_dialog_Winners sizeToFit];
        _bg_dialog_Winners.contentMode = UIViewContentModeScaleToFill;
    }
    return _bg_dialog_Winners;
}

-(UIImageView *)bg_dialog_Lose{
    if (!_bg_dialog_Lose) {
        _bg_dialog_Lose = [[UIImageView alloc]init];
        [_bg_dialog_Lose setUserInteractionEnabled:YES];
        _bg_dialog_Lose.contentMode = UIViewContentModeScaleToFill;
        [_bg_dialog_Lose sizeToFit];
    }
    return _bg_dialog_Lose;
}

-(UIImageView *)bg_dialog_WalletWinners{
    if (!_bg_dialog_WalletWinners) {
        _bg_dialog_WalletWinners = [[UIImageView alloc]init];
        [_bg_dialog_WalletWinners setUserInteractionEnabled:YES];
        [_bg_dialog_WalletWinners sizeToFit];
    }
    return _bg_dialog_WalletWinners;
}

-(UIImageView *)bg_dialog_WalletLose{
    if (!_bg_dialog_WalletLose) {
        _bg_dialog_WalletLose = [[UIImageView alloc]init];
        [_bg_dialog_WalletLose setUserInteractionEnabled:YES];
        [_bg_dialog_WalletLose sizeToFit];
    }
    return _bg_dialog_WalletLose;
}

-(UIButton *)closeButton{
    if (!_closeButton) {
        _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_closeButton setImage:[UIImage imageWithContentsOfFile:SEGPicName(@"btn_hongbao_close")] forState:UIControlStateNormal];
        [_closeButton addTarget:self action:@selector(seg_colse) forControlEvents:UIControlEventTouchUpInside];
        [_closeButton sizeToFit];
        _closeButton.hidden = YES;
    }
    return _closeButton;
}

-(UIButton *)commitButton{
    if (!_commitButton) {
        _commitButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_commitButton setTitle:@"确定" forState:UIControlStateNormal];
        [_commitButton addTarget:self action:@selector(seg_tryAgin:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _commitButton;
}

-(UIImageView *)img_dialogt{
    if (!_img_dialogt) {
        _img_dialogt = [[UIImageView alloc]initWithImage:[UIImage imageWithContentsOfFile:SEGPicName(@"img_activity01_dialogt")]];
    }
    return _img_dialogt;
}

-(UIImageView *)img_box{
    if (!_img_box) {
        _img_box = [[UIImageView alloc]initWithImage:[UIImage imageWithContentsOfFile:SEGPicName(@"pic_default_300_300")]];
        //        _img_box.backgroundColor = [UIColor redColor];
    }
    return _img_box;
}

-(UILabel *)appNameLabel{
    
    if (!_appNameLabel) {
        _appNameLabel = [[UILabel alloc]init];
        _appNameLabel.numberOfLines = 0;
        _appNameLabel.textAlignment = NSTextAlignmentCenter;
        _appNameLabel.text = kAppName;
        [_appNameLabel setFont:[UIFont systemFontOfSize:12]];
        [_appNameLabel sizeToFit];
        _appNameLabel.textColor = [UIColor colorWithRed:255.0/255.0 green:160.0/255.0 blue:0.0/255.0 alpha:1];
    }
    return _appNameLabel;
}

-(UILabel *)contentLabel{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc]init];
        _contentLabel.numberOfLines = 0;
        _contentLabel.textAlignment = NSTextAlignmentCenter;
        [_contentLabel setUserInteractionEnabled:YES];
        _contentLabel.lineBreakMode = NSLineBreakByCharWrapping;
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(seg_lotteryRecord)];
        [_contentLabel addGestureRecognizer:tap];
    }
    return _contentLabel;
}

-(UIButton *)checkAwardListBtn{
    if (!_checkAwardListBtn) {
        _checkAwardListBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _checkAwardListBtn.titleLabel.font = [UIFont systemFontOfSize:12.0];
        _checkAwardListBtn.titleLabel.lineBreakMode = NSLineBreakByCharWrapping;
        [_checkAwardListBtn setTitleColor:[UIColor colorWithRed:255.0/255.0 green:88.0/255.0 blue:88.0/255.0 alpha:1] forState:UIControlStateNormal];
        [_checkAwardListBtn setTitle:@"" forState:UIControlStateNormal];
        [_checkAwardListBtn addTarget:self action:@selector(seg_lotteryRecord) forControlEvents:UIControlEventTouchUpInside];
    }
    return _checkAwardListBtn;
}


-(UIImageView *)appNameLeftImageView{
    if (!_appNameLeftImageView) {
        _appNameLeftImageView = [[UIImageView alloc]initWithImage:[UIImage imageWithContentsOfFile:SEGPicName(@"img_hongbao_line_l")]];
        [_appNameLeftImageView sizeToFit];
    }
    return _appNameLeftImageView;
}

-(UIImageView *)appNameRightImageView{
    if (!_appNameRightImageView) {
        _appNameRightImageView = [[UIImageView alloc]initWithImage:[UIImage imageWithContentsOfFile:SEGPicName(@"img_hongbao_line_r")]];
        [_appNameRightImageView sizeToFit];
    }
    return _appNameRightImageView;
}

-(void)ddd{
    for (UIView *object in self.subviews) {
        [object removeFromSuperview];
    }
}
@end
